<%@page import="ca.uvic.group2.ui.*"%>
<%@page import="ca.uvic.group2.api.*"%>
<%@page import="java.util.*"%>


<html>
<head>
<title>Stats 2</title>
<style>
body
{
        background-color: white;
}

form
{
        margin: 0px;
        padding: 0px;
}

.loginform
{
        border: 1px solid black;
        background-color: #ccc;
        width: 50%;
        margin-left: 25%;
        margin-right: 25%;
        margin-top: 10px;
}
.errorMessage
{
        border: 1px solid #990;
        background-color: #FFA;
        margin: 5px;
}
</style>

<script>
function setFocus() { }
</script>
</head>

<body onload="setFocus();">

<h1>StockServ Stats</h1>

<%
        ArrayList statsList = (ArrayList)request.getAttribute("statsList");
        Iterator i = statsList.iterator();

        while (i.hasNext()) {
                Stats stat  = (Stats)i.next();
%>
<div class='loginform'>
<table>
<%
                if (stat.kind == Stats.TRANSACTION) {
                        out.print("<tr><td>Name</td><td>" + stat.name + "</td></tr>");
                        out.print("<tr><td>Transactions</td><td>" + String.valueOf(stat.totalTransactions) + "</td></tr>");
                        out.print("<tr><td>Errors</td><td>" + String.valueOf(stat.totalErrors) + "</td></tr>");
                        out.print("<tr><td>Error Ratio</td><td>" + String.valueOf((((float)stat.totalErrors) / (stat.totalErrors + stat.totalTransactions)) * 100.0f) + "</td></tr>");
                        out.print("<tr><td>Total Transactions</td><td>" + String.valueOf(stat.totalErrors + stat.totalTransactions) + "</td></tr>");
                        out.print("<tr><td>Transactions per second</td><td>" + String.valueOf(stat.getTransactionsPerSecond()) + "</td></tr>");
                        out.print("<tr><td>Average Processing Time</td><td>" + String.valueOf(stat.getAvgTransactionTime()) + "</td></tr>");
                        out.print("<tr><td>Trans. time (moving avg)</td><td>" + String.valueOf(stat.getMovingAvgTime()) + "</td></tr>");
                        out.print("<tr><td>Trans. per sec (moving avg)</td><td>" + String.valueOf(stat.getMovingAvgTransPerSecond()) + "</td></tr>");
                        out.print("<tr><td>Current Sessions</td><td>" + String.valueOf(stat.currentSessions) + "</td></tr>");
                        out.print("<tr><td>Max Concurrent Sessions</td><td>" + String.valueOf(stat.maxSessions) + "</td></tr>");
		} else if (stat.kind == Stats.DB) { 
                        out.print("<tr><td>Query Time (Moving Avg)</td><td>" + String.valueOf(stat.getAvgQueryTime()) + "</td></tr>");
                        out.print("<tr><td>Query Time (Commulative)</td><td>" + String.valueOf(stat.getCommAvgQueryTime()) + "</td></tr>");
                        out.print("<tr><td>Read Query Count</td><td>" + String.valueOf(stat.getReadQueryCount()) + "</td></tr>");
                        out.print("<tr><td>Write Query Count</td><td>" + String.valueOf(stat.getWriteQueryCount()) + "</td></tr>");
                        out.print("<tr><td>Queue Time (Moving Avg)</td><td>" + String.valueOf(stat.getAvgQueueTime()) + "</td></tr>");
                        out.print("<tr><td>Exe Time (Mocing Avg)</td><td>" + String.valueOf(stat.getAvgExeTime()) + "</td></tr>");
                        out.print("<tr><td>Queue Time (Commulative)</td><td>" + String.valueOf(stat.getCommAvgQueueTime()) + "</td></tr>");
                        out.print("<tr><td>Exe Time (Commulative)</td><td>" + String.valueOf(stat.getCommAvgExeTime()) + "</td></tr>");
                        out.print("<tr><td>Queue Size (Moving Avg)</td><td>" + String.valueOf(stat.getAvgQueueSize()) + "</td></tr>");
                        out.print("<tr><td>Queue Sizze (Commulative)</td><td>" + String.valueOf(stat.getCommAvgQueueSize()) + "</td></tr>");
        
                }

                out.print("<tr><td>Free Mem</td><td>" + String.valueOf(stat.getFreeMem() / 1024.0f) + "</td></tr>");
                out.print("<tr><td>Total Mem</td><td>" + String.valueOf(stat.getTotalMem() / 1024.0f) + "</td></tr>");
                out.print("<tr><td>Max Mem</td><td>" + String.valueOf(stat.getMaxMem() / 1024.0f) + "</td></tr>");

%>

</table>
</div>

<%
        }
%>

<div class='loginform'>
<form action="stockserv"><input type="submit" value="Rad."></form>
</div>

</body>
</html>
